import { createRouter, createWebHashHistory } from 'vue-router'
import HomeView from '../views/homeView.vue'
const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      redirect: '/main',
      component: HomeView,
      children: [{
        path: "/main",
        name: "main",//首页
        component: () =>
          import( /* webpackChunkName: 'homeContent' */ '../views/homeContent.vue'),
        meta: {}
      }, {
        path: '/setting',
        name: 'setting',//我的
        component: () => import(/* webpackChunkName: 'settingView' */'../views/settingView.vue')
      }]
    }, {
      path: '/query',
      name: 'query',//查询
      component: () => import('../views/queryView.vue')
    }, {
      path: '/helpCenter',
      name: 'helpCenter',//帮助中心
      component: () => import('../views/helpCenter.vue')
    }, {
      path: '/recognitionView',
      name: 'recognitionView',//识别页面
      component: () => import('../views/recognitionView.vue')
    }, {
      path: '/details',
      name: 'details',//详情
      component: () => import('../views/detailsView.vue'),
    }, {
      path: '/collect',
      name: 'collect',//我的收藏
      component: () => import('../views/collectView.vue')
    }, {
      path: '/unlawfulAct',
      name: 'unlawfulAct',//违法识别
      component: () => import('../views/unlawfulActView.vue')
    }, {
      path: '/login',
      name: 'login',//登录
      component: () => import('../views/login.vue')
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.path !== "/login") {
    if (localStorage.getItem("token")) {
      next()

    } else {
      next("/login")
    }
  } else {
    next()
  }

});
export default router
